from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import NumericProperty, ObjectProperty
from kivy.clock import Clock
from kivy.core.window import Window

class TouchWidget(Widget):
    touch_x = NumericProperty(0)
    touch_y = NumericProperty(0)

    def on_touch_down(self, touch):
        self.touch_x = touch.x
        self.touch_y = touch.y
        print(f"Touch detected at {touch.x}, {touch.y}")

        # 在这里添加自动点击的逻辑
        # 例如，模拟点击某个按钮的位置
        # 可以使用 Clock.schedule_once 来定时执行自动点击
        Clock.schedule_once(self.perform_click, 1)

    def perform_click(self, dt):
        # 假设我们要点击的位置是 (100, 100)
        x, y = 100, 100
        # 使用 Kivy 的 touch 模拟点击
        touch = Window.request_touch("perform_click", self)
        if touch:
            touch.ud['pos'] = (x, y)
            touch.apply()
            print("Simulated click at", x, y)

class TouchApp(App):
    def build(self):
        return TouchWidget()

if __name__ == '__main__':
    TouchApp().run()